/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.t4.irc;

import java.text.SimpleDateFormat;

/**
 * Logger
 * @author T4_
 *
 */
public class Logger {

    /** Debug mode on/off */
    private static final boolean DEBUG = true;

    /** The time format */
	private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");

    /** The canonical name of the class the logger instance is used for */
    private String canonicalName;

    /**
     * Creates a new logger for a given class
     * @param c
     */
    public Logger(Class<?> c) {
        this.canonicalName = c.getCanonicalName();
    }

    /**
     * The current time, formatted
     * @return
     */
    private String getCurrentTime() {
       return TIME_FORMAT.format(System.currentTimeMillis());
    }

    /**
     * Prints each object
     * @param o
     */
    public void print(Object... o) {
        for (Object m : o)
            System.out.println("[" + getCurrentTime() + "] " + canonicalName + ": " + m);
    }

    /**
     * Prints each object (error)
     * @param o
     */
    public void error(Object... o) {
        for (Object m : o)
            System.err.println("[" + getCurrentTime() + "] " + canonicalName + ": " + m);
    }


    /**
     * Prints each object if DEBUG mode is on
     * @param o
     */
    public void debug(Object... o) {
        if(!DEBUG)
            return;
        for (Object m : o)
            System.out.println("[" + getCurrentTime() + "] " + canonicalName + ": " + m);
    }

}
